Dog Breed Classifier

In this notebook, we explore the dog breed classifier algorithm and break down each step of the pipeline with some analysis

0. Load Data

Load Dog Dataset

Looking at the training data class distribution, we see that the classes are not entirely even but the distribution does not look too unbalanced

Load Human Dataset

1. Human Detector

Here we consider two human face detectors, Haar feature-based cascade classifiers and Face recognition using PyTorch.

For our assessment we consider four metrics:

We see that overall the Haar Cascade algorithm does better than MTCNN on all metrics

2. Dog Detector

Here we look at potential dog detectors. We consider convolutional neural network models pretrained on ImageNet. For metrics we use the same as we used for the human detector.

We see that overall VGG16 beats the other models

3. Dog Breed Classifier From Scratch

In this section, we design a convolutional neural network model to classify dog breeds. We then train and evaluate our model. Evaluation is carried out using the same metrics as before. However, note in this class we are dealing with a multi-class problem (instead of binary).

During the training of our model, we augment our data by

We fix our model to train for 20 epochs with cross entropy loss and Adam optimizer with a learning rate of 3e-4. We also regularly validate the model on the validation set and keep the model with the lowest validation score as our chosen model.

Hmm, our results don't look too satisfactory

4. Dog Breed Classifier With Transfer Learning

Now, we modify our method with a transfer learning solution. We use popular pretrained models and modify their final layers to suit our prolblem. Then we freeze the feature extraction layers and train only the final layers. Besides the model, the training setup is similar to before. We compare transfer learning on VGG16 as well as ResNet50.

For the VGG16 pretrained model, please download it from here.

Using transfer learning we've managed to increase our accuracy from 12% to 83%!. Notice that the ResNet50 model with transfer learning is overall better than the VGG16 model with transfer learning given our chosen metrics. It is expected that the VGG16 model does better than the ResNet50 model given that it has more parameters. However, given that VGG16 has more parameters it would also need more time and data to train.

Final Algorithm

Finally, we put everything together to develop an algorithm that takes in an image and identifies if contains a human or a dog. If it does contain either a human or a dog, a convolutional neural network (CNN) will classify the dog's breed or the resembling dog breed for that human.